﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Modeling_Sub_Pages_NewsPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        UniversityDatabaseManagerment udm = new UniversityDatabaseManagerment();

        if (Session["WelcomeUser"] != null)
        {
            if (Session["EmployeeID"] != null && Session["Role"].ToString().Equals("EAS"))
            {
                if (udm.createConnection() != null)
                {
                    if (!IsPostBack)
                    {
                        GridView1.DataSource = udm.showCoursesForMaintainEventEnd(udm.createConnection());
                        GridView1.DataBind();

                        ddlTeacher.DataSource = udm.showTeacher(udm.createConnection());
                        ddlTeacher.DataTextField = "Full Name";
                        ddlTeacher.DataValueField = "ID";
                        ddlTeacher.DataBind();
                        ddlTeacher.Items.Insert(0, new ListItem("All Department", "-1"));

                        ddlSubject.DataSource = udm.showSubject(udm.createConnection());
                        ddlSubject.DataTextField = "Name";
                        ddlSubject.DataValueField = "ID";
                        ddlSubject.DataBind();
                        ddlSubject.Items.Insert(0, new ListItem("All Position", "NA"));
                    }
                }
                else
                {
                    Response.Redirect("~/ErrorPage.aspx");
                }
            }
            else
            {
                Response.Redirect("~/LoginMessage.aspx?id=1");
            }
        }
        else
        {
            Response.Redirect("~/Login.aspx?id=2");
        }
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataBind();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        UniversityDatabaseManagerment udm = new UniversityDatabaseManagerment();

        string name = txtTitle.Text;
        string subjectID = ddlSubject.SelectedValue;
        int teacherID = Convert.ToInt32(ddlTeacher.SelectedValue);

        GridView1.DataSource = udm.searchCourseEventEnd(udm.createConnection(), name, subjectID, teacherID);
        GridView1.DataBind();
    }
}